<template>
  <basic-container>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <i class="el-icon-setting"></i> 库存上报
        </el-breadcrumb-item>
        <el-breadcrumb-item>
          <i class="el-icon-date"></i> 审核
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <avue-form ref="form" v-model="form" :option="reviewOption">
      <template slot-scope="scope" slot="menuForm">
        <el-button type="success" @click="handleSuccess(detailForm.reportSn)">通 过</el-button>
        <el-button type="warning" @click="handleFailed(detailForm.reportSn)">不通过</el-button>
        <el-button @click="goBack">返 回</el-button>
      </template>
    </avue-form>
    <avue-detail ref="detail_form" v-model="detailForm" :option="option"></avue-detail>
    <!--  <avue-crud ref="crud" :option="orderDetailOption" :data="orderDetailList"></avue-crud> -->
  </basic-container>
</template>

<script>
import { getDetail, sureReport } from "@/api/crm/rep";
//     import {fetchInfo, reviewFailed, reviewSuccess} from '../../api/bill/receivable';
// 基本信息
import { formOption } from "../../../const/crud/crm/reporting/receivable";
// 通过不通过
import { formOption as reviewOption } from "../../../const/crud/crm/reporting/review";
// 列表
import { formOption as orderDetailOption } from "../../../const/crud/crm/reporting/order-review";
import { goBack } from "../../../util/util";

export default {
  data() {
    return {
      form: {},
      detailForm: {},
      option: formOption,
      reviewOption: reviewOption,
      orderDetailOption: orderDetailOption,
      orderDetailList: []
    };
  },
  computed: {},
  created() {},
  //   beforeRouteEnter(to, from, next) {
  //     next(vm => {
  //       vm.form.billSn = vm.$route.query.res.billSn;
  //       vm.getReview(vm.$route.query.res.billSn);
  //     });
  //   },
  beforeRouteEnter(to, from, next) {
    next(vm => vm.getReview(vm.$route.query.res.reportSn));
  },
  methods: {
    getReview(reportSn) {
      getDetail({ reportSn: reportSn }).then(res => {
        console.log(res);
        this.detailForm = res.data.data;
        this.detailList = res.data.data.detailList;
      });
    },

    handleSuccess(reportSn) {
      let params = {
        reportSn: reportSn,
        confirmFlag:true,
        remarks: this.form.remarks
      };

      console.log(reportSn, this.form, params);
      sureReport(params).then(res => {
        console.log(res);
        if (res.data.code === 0 && res.data.data) {
          this.$message.success("审核通过, 操作成功");
          this.goBack();
        } else {
          this.$message.success(res.data.msg);
        }
      });
    },
    handleFailed(reportSn) {
      let params = {
        reportSn: reportSn,
        confirmFlag:false,
        remarks: this.form.remarks
      };
      sureReport(params).then(res => {
        console.log(res);
        if (res.data.code === 0 && res.data.data) {
          this.$message.success("审核不通过, 操作成功");
          this.goBack();
        } else {
          this.$message.success(res.data.msg);
        }
      });
    },
    goBack(time = 1000) {
      goBack(this, time);
    }
  }
};
</script>

<style scoped lang="scss">
.crumbs {
  margin: 20px 10px;
}
</style>


